package com.peanut.devlibrary.util;

/**
 * Created by anonymouslystudio on 2017/6/6.
 */

public class StringUtil {

    /**
     * is str is null or empty
     * @param str
     * @return
     */
    public static boolean isNullOrEmpty(String str) {
        return str == null || str.trim().length() == 0;
    }

    /**
     * is str is mobile format
     * @param str
     * @return
     */
    public static boolean isMobile(String str) {

        return str != null
                && (str.matches("(\\+86|86|0086)?(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])\\d{8}"));

//        return str != null
//                && (str.matches("(\\+86|86|0086)?(13[0-9]|15[0-35-9]|14[57]|18[012356789]|17[036789])\\d{8}")
//                || str.matches("(\\+86|86|0086)?(1000000[0-9])\\d{3}"));
    }

    public static boolean isMobileNumbric(String str) {

        return str != null
                && (str.matches("[0-9]*")) && str.length() == 11;
    }

    /**
     * is password format (character length 6~20 only a~z ,A~Z and 0~9 accepted)
     * @param str
     * @return
     */
    public static boolean isPassword(String str) {
        return str != null
                && str.matches("[\\da-zA-Z]{6,20}");

    }

    public static String getSimpleText(String richText){
        String regex = "<img[^>]*>";

        return richText.replaceAll(regex, "");
    }
}
